package cn.zqy.demo.day07;

import java.util.ArrayList;
import java.util.Random;

public class Demo09ArrayListReturn {
    public static void main(String[] args) {
        Random r = new Random();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            // 存入20个0~99之间的数
            list.add(r.nextInt(100));
        }
        ArrayList<Integer> arr = selectOdd(list);
        System.out.println(list);
        System.out.println(arr);
    }

    public static ArrayList<Integer> selectOdd(ArrayList<Integer> list) {
        ArrayList<Integer> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) % 2 == 0) {
                newList.add(list.get(i));
            }
        }
        return newList;
    }
}
